package org.vt.ece3574.pictoslider.menus;

import org.vt.ece3574.pictoslider.GameScreen;
import org.vt.ece3574.pictoslider.PictureFileManager;
import org.vt.ece3574.pictoslider.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

/**
 * This class represents the activity for the app's Main Menu. The layout
 * details are in main.xml, where each button's on click handler is defined. The
 * methods in this class listen for button clicks and launch the appropriate
 * activity when a click occurs.
 * 
 * @author Michael Drescher
 */
public class MainMenu extends Activity {

	/**
	 * Used to determine if a theme change occured while in the Settings Menu.
	 */
	private static final int THEME_CHANGE = 1;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Themes.setThemePos(getSharedPreferences(SettingsMenu.SETTINGS_PREFS, 0)
				.getInt(SettingsMenu.THEME, Themes.DEFAULT_THEME));
		Themes.onActivityCreateSetTheme(this);
		Themes.onActivityCreateSetContentView(this, R.layout.main);
		PictureFileManager pfm = new PictureFileManager(getApplicationContext());
		pfm.write(null);
	}

	/** Called when the Quickstart button is pressed. */
	public void goToQuickstart(View v) {
		Intent intent = new Intent(this, GameScreen.class);
		startActivity(intent);
	}

	/** Called when the Game Modes button is pressed. */
	public void goToGameModes(View v) {
		Intent intent = new Intent(this, GameMenu.class);
		startActivity(intent);
	}

	/** Called when the Settings button is pressed. */
	public void goToSettings(View v) {
		Intent intent = new Intent(this, SettingsMenu.class);
		startActivityForResult(intent, THEME_CHANGE);
	}

	/** Called when the High Scores button is pressed. */
	public void goToHighScores(View v) {
		Intent intent = new Intent(this, HighScoreScreen.class);
		startActivity(intent);
	}

	/** Called when the About button is pressed. */
	public void goToAbout(View v) {
		Intent intent = new Intent(this, AboutScreen.class);
		startActivity(intent);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == THEME_CHANGE) {
			finish();
			startActivity(new Intent(this, MainMenu.class));
		}
	}
}